﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Employee_feb
{

//  Объявить базовый класс Employee.Класс содержит поле name и абстрактный метод CalculateSalary().
//Объявить два класса наследника: 
//1) Worker - класс содержит поле yearSalary и реализует метод CalculateSalary(). 
//  Метод должен выводить на экран имя сотрудника и месячную зарплату(yearSalary/12)
//2) HourlyWorker -  класс содержит поля rate и hours и реализует метод CalculateSalary().
//  Метод должен выводить на экран имя сотрудника и количество денег для выплаты(rate* hours)
    class Program
    {
        static void Main(string[] args)
        {
            List<Employee> employees = new List<Employee>();
            employees.Add(new Worker("Antonio Banderas", 1200000));
            employees.Add(new Worker("Tom Cruise", 2000000));
            employees.Add(new Worker("Fedor Bondarchuk", 20000));
            employees.Add(new HourlyWorker("Danny Trejo", 200, 45));
            employees.Add(new HourlyWorker(" Robert Anthony Rodriguez", 300, 35.5));
            employees.Add(new HourlyWorker("Zoë Bell", 700, 89.2));

            foreach (var buddy in employees)
            {
                buddy.CalculateSalary();
            }
            Console.ReadLine();
        }
    }

   abstract class Employee
    {
        private string name;

        public Employee (string name)
        {
            this.name = name;
        }

        public abstract void CalculateSalary();
        
        public string GetName
        {
            get
            {
                return name;
            }
            set
            {
                if (String.IsNullOrWhiteSpace(value))
                throw new InvalidOperationException("Name can't be null");
                name = value;
            }
        }
    }

    class Worker : Employee
    {
        private double yearSalary;

        public Worker (string name, double yearSalary) : base(name)
        {
            this.yearSalary = yearSalary;
        }

        public override void CalculateSalary()
        {
            Console.WriteLine("Worker's name : {0}, yearly rate: {1}", GetName, yearSalary);
        }
    }


    class HourlyWorker : Employee
    {
        private double rate;
        private double hours;

        public HourlyWorker (string name, double rate, double hours): base(name)
        {
            this.rate = rate;
            this.hours = hours;
        }

        public double GetRate
        {
            get
            {
                return rate;
            }
            set
            {
                if (value < 0)
                {
                    throw new InvalidOperationException("Rate can't be less than zero");
                }
                else
                {
                    rate = value;
                }
            }
        }

        public double GetHhours
        {
            get
            {
                return hours;
            }
            set
            {
                if (value < 0)
                {
                    throw new InvalidOperationException("Hours can't be less than zero");
                }
                else
                {
                    hours = value;
                }
            }
        }

        public override void CalculateSalary()
        {
            Console.WriteLine("Worker's name : {0}, rate: {1}, hours : {2}", GetName, rate, hours);
            Console.WriteLine("Money for him to get: {0}", hours * rate);
        }
    }
    
}
